<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Mockery\Exception;

class DoctorExpert extends Model
{
    public $timestamps = false;
    protected $table = 'jkbl_doctorexpert';


    //显示状态
    const STATUS_OFF = 0;
    const STATUS_ON = 1;

    static $StatusDisplay = [
        self::STATUS_OFF => '不显示',
        self::STATUS_ON => '显示',
    ];

    /**
     * 添加擅长领域
     * @param $request
     * @return array
     */
    static function DoctorExpertPublish($request)
    {
        try {
            $type = new DoctorExpert();
            $type->title = $request->title;
            $type->display = $request->display;
            $type->status = $request->status;
            $type->bordercolor = $request->bordercolor;
            $type->createtime = time();
            if (!$type->save()) {
                return error('添加失败');
            }
            return success('添加成功');
        } catch (Exception $exception) {
            return error();
        }
    }


    /**
     * 擅长领域
     * @param $ids
     * @return string
     */
    static function DoctorExperts($ids)
    {
        if (!$ids) {
            return '';
        }

        $arr_id = array_filter(explode(',', $ids));
        $experts = DoctorExpert::whereIn('id', $arr_id)->pluck('title')->toArray();
        return join(',', $experts);
    }

}
